<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="billcode">
        <el-input
          v-model="queryParams.billcode"
          placeholder="请输入单据编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="dates">
        <el-input
          v-model="queryParams.dates"
          placeholder="请输入日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="businessname">
        <el-input
          v-model="queryParams.businessname"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品编号" prop="goodscode">
        <el-input
          v-model="queryParams.goodscode"
          placeholder="请输入商品编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="goodsname">
        <el-input
          v-model="queryParams.goodsname"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['flow:htxsml:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['flow:htxsml:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['flow:htxsml:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['flow:htxsml:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="htxsmlList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="机构名称" align="center" prop="orgname" />
      <el-table-column label="单据类别" align="center" prop="summaries" />
      <el-table-column label="单据编号" align="center" prop="billcode" />
      <el-table-column label="日期" align="center" prop="dates" />
      <el-table-column label="单位名称" align="center" prop="businessname" />
      <el-table-column label="单位编号" align="center" prop="businesscode" />
      <el-table-column label="客户类别" align="center" prop="clienttype" />
      <el-table-column label="商品编号" align="center" prop="goodscode" />
      <el-table-column label="商品名称" align="center" prop="goodsname" />
      <el-table-column label="商品规格" align="center" prop="goodsspec" />
      <el-table-column label="生产厂家" align="center" prop="manufacturer" />
      <el-table-column label="部门名称" align="center" prop="department" />
      <el-table-column label="库房名称" align="center" prop="whname" />
      <el-table-column label="批号" align="center" prop="batchcode" />
      <el-table-column label="数量" align="center" prop="num" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="含税价" align="center" prop="taxprice" />
      <el-table-column label="含税金额" align="center" prop="taxamount" />
      <el-table-column label="批次含税价" align="center" prop="batchtaxprice" />
      <el-table-column label="成本金额" align="center" prop="taxcostamt" />
      <el-table-column label="含税售价" align="center" prop="saletaxp" />
      <el-table-column label="单品毛利" align="center" prop="profitOne" />
      <el-table-column label="毛利" align="center" prop="profit" />
      <el-table-column label="毛利率" align="center" prop="profitrate" />
      <el-table-column label="销售员" align="center" prop="ywyname" />
      <el-table-column label="开票员" align="center" prop="kpname" />
      <el-table-column label="负责人编号" align="center" prop="ownercoden" />
      <el-table-column label="负责人" align="center" prop="ownernamen" />
      <el-table-column label="商品分类" align="center" prop="goodsflname" />
      <el-table-column label="参考标识" align="center" prop="ckremark" />
      <el-table-column label="线路ID" align="center" prop="routeId" />
      <el-table-column label="发票类型" align="center" prop="invoicelx" />
      <el-table-column label="发票方式" align="center" prop="invoicetype" />
      <el-table-column label="付款方式" align="center" prop="paytype" />
      <el-table-column label="账期分类" align="center" prop="zhangqfl" />
      <el-table-column label="采购员" align="center" prop="cgyname" />
      <el-table-column label="供货商" align="center" prop="gysname" />
      <el-table-column label="协议政策" align="center" prop="lxremark" />
      <el-table-column label="发票完成" align="center" prop="isinvoice" />
      <el-table-column label="税率" align="center" prop="rate" />
      <el-table-column label="发票管理登记号" align="center" prop="invoicectrno" />
      <el-table-column label="发票日期" align="center" prop="invoicedate" />
      <el-table-column label="信贷天数" align="center" prop="xindts" />
      <el-table-column label="清" align="center" prop="Issettle" />
      <el-table-column label="单据序号" align="center" prop="billsn" />
      <el-table-column label="是否确认" align="center" prop="Isconfirm" />
      <el-table-column label="备注地址" align="center" prop="remarkaddress" />
      <el-table-column label="发货方式" align="center" prop="delivery" />
      <el-table-column label="支付方式名称" align="center" prop="paymetname" />
      <el-table-column label="协议返点" align="center" prop="zdprice" />
      <el-table-column label="放弃理由描述" align="center" prop="reason" />
      <el-table-column label="统计分类" align="center" prop="clientsort" />
      <el-table-column label="确认日期" align="center" prop="confirmdate" />
      <el-table-column label="确认人" align="center" prop="confirmname" />
      <el-table-column label="原含税价" align="center" prop="oldtaxprice" />
      <el-table-column label="仓储包装规格" align="center" prop="wmsmeas" />
      <el-table-column label="是否手动定价" align="center" prop="issddj" />
      <el-table-column label="手动商品定价依据" align="center" prop="princingbasis" />
      <el-table-column label="是否次月付" align="center" prop="isyf" />
      <el-table-column label="品牌ID" align="center" prop="brandid" />
      <el-table-column label="中和平均含税进价" align="center" prop="avgpurtaxp" />
      <el-table-column label="是否综合定价" align="center" prop="sfzhdj" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['flow:htxsml:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['flow:htxsml:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改恒泰销售毛利查询对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="条目数" prop="xh">
          <el-input v-model="form.xh" placeholder="请输入条目数" />
        </el-form-item>
        <el-form-item label="单据ID" prop="billno">
          <el-input v-model="form.billno" placeholder="请输入单据ID" />
        </el-form-item>
        <el-form-item label="企业ID" prop="entid">
          <el-input v-model="form.entid" placeholder="请输入企业ID" />
        </el-form-item>
        <el-form-item label="机构名称" prop="orgname">
          <el-input v-model="form.orgname" placeholder="请输入机构名称" />
        </el-form-item>
        <el-form-item label="单据类别" prop="summaries">
          <el-input v-model="form.summaries" placeholder="请输入单据类别" />
        </el-form-item>
        <el-form-item label="单据编号" prop="billcode">
          <el-input v-model="form.billcode" placeholder="请输入单据编号" />
        </el-form-item>
        <el-form-item label="日期" prop="dates">
          <el-input v-model="form.dates" placeholder="请输入日期" />
        </el-form-item>
        <el-form-item label="单位名称" prop="businessname">
          <el-input v-model="form.businessname" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="单位编号" prop="businesscode">
          <el-input v-model="form.businesscode" placeholder="请输入单位编号" />
        </el-form-item>
        <el-form-item label="商品编号" prop="goodscode">
          <el-input v-model="form.goodscode" placeholder="请输入商品编号" />
        </el-form-item>
        <el-form-item label="商品名称" prop="goodsname">
          <el-input v-model="form.goodsname" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="商品规格" prop="goodsspec">
          <el-input v-model="form.goodsspec" placeholder="请输入商品规格" />
        </el-form-item>
        <el-form-item label="生产厂家" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入生产厂家" />
        </el-form-item>
        <el-form-item label="部门名称" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门名称" />
        </el-form-item>
        <el-form-item label="库房名称" prop="whname">
          <el-input v-model="form.whname" placeholder="请输入库房名称" />
        </el-form-item>
        <el-form-item label="批号" prop="batchcode">
          <el-input v-model="form.batchcode" placeholder="请输入批号" />
        </el-form-item>
        <el-form-item label="数量" prop="num">
          <el-input v-model="form.num" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="含税价" prop="taxprice">
          <el-input v-model="form.taxprice" placeholder="请输入含税价" />
        </el-form-item>
        <el-form-item label="含税金额" prop="taxamount">
          <el-input v-model="form.taxamount" placeholder="请输入含税金额" />
        </el-form-item>
        <el-form-item label="批次含税价" prop="batchtaxprice">
          <el-input v-model="form.batchtaxprice" placeholder="请输入批次含税价" />
        </el-form-item>
        <el-form-item label="成本金额" prop="taxcostamt">
          <el-input v-model="form.taxcostamt" placeholder="请输入成本金额" />
        </el-form-item>
        <el-form-item label="含税售价" prop="saletaxp">
          <el-input v-model="form.saletaxp" placeholder="请输入含税售价" />
        </el-form-item>
        <el-form-item label="单品毛利" prop="profitOne">
          <el-input v-model="form.profitOne" placeholder="请输入单品毛利" />
        </el-form-item>
        <el-form-item label="毛利" prop="profit">
          <el-input v-model="form.profit" placeholder="请输入毛利" />
        </el-form-item>
        <el-form-item label="毛利率" prop="profitrate">
          <el-input v-model="form.profitrate" placeholder="请输入毛利率" />
        </el-form-item>
        <el-form-item label="销售员" prop="ywyname">
          <el-input v-model="form.ywyname" placeholder="请输入销售员" />
        </el-form-item>
        <el-form-item label="开票员" prop="kpname">
          <el-input v-model="form.kpname" placeholder="请输入开票员" />
        </el-form-item>
        <el-form-item label="负责人编号" prop="ownercoden">
          <el-input v-model="form.ownercoden" placeholder="请输入负责人编号" />
        </el-form-item>
        <el-form-item label="负责人" prop="ownernamen">
          <el-input v-model="form.ownernamen" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="商品分类" prop="goodsflname">
          <el-input v-model="form.goodsflname" placeholder="请输入商品分类" />
        </el-form-item>
        <el-form-item label="参考标识" prop="ckremark">
          <el-input v-model="form.ckremark" placeholder="请输入参考标识" />
        </el-form-item>
        <el-form-item label="线路ID" prop="routeId">
          <el-input v-model="form.routeId" placeholder="请输入线路ID" />
        </el-form-item>
        <el-form-item label="发票类型" prop="invoicelx">
          <el-input v-model="form.invoicelx" placeholder="请输入发票类型" />
        </el-form-item>
        <el-form-item label="账期分类" prop="zhangqfl">
          <el-input v-model="form.zhangqfl" placeholder="请输入账期分类" />
        </el-form-item>
        <el-form-item label="采购员" prop="cgyname">
          <el-input v-model="form.cgyname" placeholder="请输入采购员" />
        </el-form-item>
        <el-form-item label="供货商" prop="gysname">
          <el-input v-model="form.gysname" placeholder="请输入供货商" />
        </el-form-item>
        <el-form-item label="协议政策" prop="lxremark">
          <el-input v-model="form.lxremark" placeholder="请输入协议政策" />
        </el-form-item>
        <el-form-item label="发票完成" prop="isinvoice">
          <el-input v-model="form.isinvoice" placeholder="请输入发票完成" />
        </el-form-item>
        <el-form-item label="税率" prop="rate">
          <el-input v-model="form.rate" placeholder="请输入税率" />
        </el-form-item>
        <el-form-item label="发票管理登记号" prop="invoicectrno">
          <el-input v-model="form.invoicectrno" placeholder="请输入发票管理登记号" />
        </el-form-item>
        <el-form-item label="发票日期" prop="invoicedate">
          <el-input v-model="form.invoicedate" placeholder="请输入发票日期" />
        </el-form-item>
        <el-form-item label="信贷天数" prop="xindts">
          <el-input v-model="form.xindts" placeholder="请输入信贷天数" />
        </el-form-item>
        <el-form-item label="清" prop="Issettle">
          <el-input v-model="form.Issettle" placeholder="请输入清" />
        </el-form-item>
        <el-form-item label="单据序号" prop="billsn">
          <el-input v-model="form.billsn" placeholder="请输入单据序号" />
        </el-form-item>
        <el-form-item label="是否确认" prop="Isconfirm">
          <el-input v-model="form.Isconfirm" placeholder="请输入是否确认" />
        </el-form-item>
        <el-form-item label="备注地址" prop="remarkaddress">
          <el-input v-model="form.remarkaddress" placeholder="请输入备注地址" />
        </el-form-item>
        <el-form-item label="发货方式" prop="delivery">
          <el-input v-model="form.delivery" placeholder="请输入发货方式" />
        </el-form-item>
        <el-form-item label="支付方式名称" prop="paymetname">
          <el-input v-model="form.paymetname" placeholder="请输入支付方式名称" />
        </el-form-item>
        <el-form-item label="协议返点" prop="zdprice">
          <el-input v-model="form.zdprice" placeholder="请输入协议返点" />
        </el-form-item>
        <el-form-item label="放弃理由描述" prop="reason">
          <el-input v-model="form.reason" placeholder="请输入放弃理由描述" />
        </el-form-item>
        <el-form-item label="统计分类" prop="clientsort">
          <el-input v-model="form.clientsort" placeholder="请输入统计分类" />
        </el-form-item>
        <el-form-item label="确认日期" prop="confirmdate">
          <el-input v-model="form.confirmdate" placeholder="请输入确认日期" />
        </el-form-item>
        <el-form-item label="确认人" prop="confirmname">
          <el-input v-model="form.confirmname" placeholder="请输入确认人" />
        </el-form-item>
        <el-form-item label="原含税价" prop="oldtaxprice">
          <el-input v-model="form.oldtaxprice" placeholder="请输入原含税价" />
        </el-form-item>
        <el-form-item label="仓储包装规格" prop="wmsmeas">
          <el-input v-model="form.wmsmeas" placeholder="请输入仓储包装规格" />
        </el-form-item>
        <el-form-item label="是否手动定价" prop="issddj">
          <el-input v-model="form.issddj" placeholder="请输入是否手动定价" />
        </el-form-item>
        <el-form-item label="手动商品定价依据" prop="princingbasis">
          <el-input v-model="form.princingbasis" placeholder="请输入手动商品定价依据" />
        </el-form-item>
        <el-form-item label="是否次月付" prop="isyf">
          <el-input v-model="form.isyf" placeholder="请输入是否次月付" />
        </el-form-item>
        <el-form-item label="品牌ID" prop="brandid">
          <el-input v-model="form.brandid" placeholder="请输入品牌ID" />
        </el-form-item>
        <el-form-item label="中和平均含税进价" prop="avgpurtaxp">
          <el-input v-model="form.avgpurtaxp" placeholder="请输入中和平均含税进价" />
        </el-form-item>
        <el-form-item label="是否综合定价" prop="sfzhdj">
          <el-input v-model="form.sfzhdj" placeholder="请输入是否综合定价" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listHtxsml, getHtxsml, delHtxsml, addHtxsml, updateHtxsml } from "@/api/flow/htxsml";

export default {
  name: "Htxsml",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 恒泰销售毛利查询表格数据
      htxsmlList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        billcode: null,
        dates: null,
        businessname: null,
        goodscode: null,
        goodsname: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询恒泰销售毛利查询列表 */
    getList() {
      this.loading = true;
      listHtxsml(this.queryParams).then(response => {
        this.htxsmlList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        xh: null,
        billno: null,
        entid: null,
        orgname: null,
        summaries: null,
        billcode: null,
        dates: null,
        businessname: null,
        businesscode: null,
        clienttype: null,
        goodscode: null,
        goodsname: null,
        goodsspec: null,
        manufacturer: null,
        department: null,
        whname: null,
        batchcode: null,
        num: null,
        unit: null,
        taxprice: null,
        taxamount: null,
        batchtaxprice: null,
        taxcostamt: null,
        saletaxp: null,
        profitOne: null,
        profit: null,
        profitrate: null,
        ywyname: null,
        kpname: null,
        ownercoden: null,
        ownernamen: null,
        goodsflname: null,
        ckremark: null,
        routeId: null,
        invoicelx: null,
        invoicetype: null,
        paytype: null,
        zhangqfl: null,
        cgyname: null,
        gysname: null,
        lxremark: null,
        isinvoice: null,
        rate: null,
        invoicectrno: null,
        invoicedate: null,
        xindts: null,
        Issettle: null,
        billsn: null,
        Isconfirm: null,
        remarkaddress: null,
        delivery: null,
        paymetname: null,
        zdprice: null,
        reason: null,
        clientsort: null,
        confirmdate: null,
        confirmname: null,
        oldtaxprice: null,
        wmsmeas: null,
        issddj: null,
        princingbasis: null,
        isyf: null,
        brandid: null,
        avgpurtaxp: null,
        sfzhdj: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.xh)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加恒泰销售毛利查询";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const xh = row.xh || this.ids
      getHtxsml(xh).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改恒泰销售毛利查询";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.xh != null) {
            updateHtxsml(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHtxsml(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const xhs = row.xh || this.ids;
      this.$modal.confirm('是否确认删除恒泰销售毛利查询编号为"' + xhs + '"的数据项？').then(function() {
        return delHtxsml(xhs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('flow/htxsml/export', {
        ...this.queryParams
      }, `htxsml_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
